#include <iostream>
using namespace std;

int ans[10000004];

int main()
{
    int p1, p2, minv, tail, v1, v2;
    ans[1] = 1;
    p1 = 1;
    p2 = 1;
    tail = 1;
    while (tail <= 10000000)
    {
        v1 = ans[p1] * 2 + 1;
        v2 = ans[p2] * 3 + 1;
        minv = v1 < v2 ? v1 : v2;
        ans[++tail] = minv;
        if (v1 == minv) p1++;
        if (v2 == minv) p2++;
    }     
    while (cin>> p1)
    	cout << ans[p1] << endl;
    
 
       
}    